package qmm.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import qmm.dao.UserDao;
import qmm.dao.impl.UserDaoImpl;
import qmm.util.JdbcUtil;

@WebServlet("/RegistServlet")
public class RegistServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public RegistServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		//获取表单数据
		String account = request.getParameter("account");
		String password = request.getParameter("password");
		String email = request.getParameter("email");
		String phone = request.getParameter("phone");
		String recommend = request.getParameter("recommend");
		String recommendId = request.getParameter("recommendId");
		String code = request.getParameter("code");
		
		UserDao dao = new UserDaoImpl();
		int n = dao.add(account, password, email, phone);
		if(n>0){
			session.removeAttribute("registMsg");//注册成功删除错误消息
			response.sendRedirect("login.jsp");
		}else{
			session.setAttribute("registMsg", "注册失败");
			response.sendRedirect("regist.jsp");
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
